<script setup lang="ts">
import { computed } from "vue";
import { useRouter, useRoute } from "vue-router";
import { useExperimentStore } from "@/stores/experimentStore";

const router = useRouter();
const route = useRoute();
const experimentStore = useExperimentStore();

// 首先尝试从路由参数中获取ID
const currentExperimentId = computed(() => {
  // 如果是通过路径参数传入的ID
  if (route.params.id) {
    return route.params.id as string;
  }

  // 如果是通过路由名称匹配
  const routeName = route.name as string;
  const experiment = experimentStore.experiments.find(
    (exp) => exp.route === routeName
  );
  return experiment?.id || "";
});

const currentExperiment = computed(() =>
  experimentStore.experiments.find(
    (exp) => exp.id === currentExperimentId.value
  )
);

function goHome() {
  router.push("/");
}
</script>

<template>
  <div class="coming-soon-view">
    <div class="coming-soon-content">
      <div v-if="currentExperiment" class="experiment-info">
        <div class="experiment-icon">{{ currentExperiment.icon || "🧪" }}</div>
        <h1 class="experiment-title">{{ currentExperiment.name }}</h1>
        <div class="coming-soon-badge">即将推出</div>
        <p class="experiment-description">
          {{ currentExperiment.description }}
        </p>
      </div>
      <div v-else class="experiment-info">
        <div class="experiment-icon">🧪</div>
        <h1 class="experiment-title">未知实验</h1>
        <div class="coming-soon-badge">即将推出</div>
        <p class="experiment-description">该实验信息不存在或已被移除</p>
      </div>

      <div class="development-status">
        <h2 class="status-title">开发状态</h2>
        <div class="status-progress">
          <div class="progress-bar">
            <div class="progress-indicator" style="width: 30%"></div>
          </div>
          <div class="progress-label">开发中 (30%)</div>
        </div>
        <p class="status-message">
          我们正在努力开发这个实验的数据处理功能。感谢您的耐心等待！
        </p>
      </div>

      <div class="actions">
        <button class="back-button" @click="goHome">返回首页</button>
      </div>
    </div>
  </div>
</template>

<style scoped>
.coming-soon-view {
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

.coming-soon-content {
  max-width: 40rem;
  width: 100%;
}

.experiment-info {
  text-align: center;
  margin-bottom: 2.5rem;
}

.experiment-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.experiment-title {
  font-size: 1.875rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.75rem;
}

.coming-soon-badge {
  display: inline-block;
  background-color: #3b82f6;
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  margin-bottom: 1rem;
}

.experiment-description {
  font-size: 1.125rem;
  color: #4b5563;
  line-height: 1.7;
}

.development-status {
  background-color: #f9fafb;
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.status-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 1.25rem;
}

.status-progress {
  margin-bottom: 1rem;
}

.progress-bar {
  height: 0.5rem;
  background-color: #e5e7eb;
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-indicator {
  height: 100%;
  background-color: #3b82f6;
  border-radius: 9999px;
}

.progress-label {
  font-size: 0.875rem;
  color: #6b7280;
  text-align: right;
}

.status-message {
  font-size: 0.9375rem;
  color: #4b5563;
  line-height: 1.6;
}

.actions {
  display: flex;
  justify-content: center;
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  background-color: #2563eb;
  color: white;
  font-weight: 500;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
  border: none;
  cursor: pointer;
}

.back-button:hover {
  background-color: #1d4ed8;
}

@media (max-width: 640px) {
  .experiment-title {
    font-size: 1.5rem;
  }

  .experiment-description {
    font-size: 1rem;
  }
}
</style>
